<!--
    Inside Double Brackets:
    fancybox path="path" file="file" caption="caption" gallery="gallery"
    fancybox "path" "file" "caption" "gallery"
    # of Params: 2-4
    Positional or Named
    position 0, name: path
        Can pass in the following values:
            title: will use /img/LinkTitle as the path
            date: will use /img/Year/Month as the path
            /path/to/img: can pass in explicit path to the image
    position 1, name: file
        Name of the file including the file extension
    position 2, name: caption
        Text for the caption of the image
    position 3, name: gallery
        Name of the gallery the image should be included in
-->
{{ $numOfParams := len .Params}}
{{ if and (ge $numOfParams 2) (le $numOfParams 4) }}
  {{ if .IsNamedParams }}
    {{ $.Scratch.Set "path" (.Get "path") }}
    {{ $.Scratch.Set "file" (.Get "file") }}
    {{ $.Scratch.Set "caption"  (.Get "caption") }}
    {{ $.Scratch.Set "gallery" (.Get "gallery") }}
  {{ else }}
    {{ $.Scratch.Set "path" (.Get 0) }}
    {{ $.Scratch.Set "file" (.Get 1) }}
    {{ if ge $numOfParams 3 }}
      {{ $.Scratch.Set "caption" (.Get 2) }}
    {{ else }}
      {{ $.Scratch.Set "caption" "" }}
    {{ end }}
    {{ if ge $numOfParams 4 }}
      {{ $.Scratch.Set "gallery" (.Get 3) }}
    {{ else }}
      {{ $.Scratch.Set "gallery" ""}}
    {{ end }}
  {{ end }}
  {{ $.Scratch.Set "structType" "shortcode" }}
  {{ $path := $.Scratch.Get "path" }}
  {{ if eq $path "date" }}
    {{ $.Scratch.Set "path" "/img/" }}
    {{ $.Scratch.Add "path" (.Page.Date.Format "2006/01") }}
  {{ end }}
  {{ $path := $.Scratch.Get "path" }}
  {{ $file := $.Scratch.Get "file" }}
  {{ $caption  := $.Scratch.Get "caption" }}
  {{ $gallery := $.Scratch.Get "gallery" }}
  <div class="fancybox">
    <a data-fancybox="{{ $gallery }}" href="{{ path.Join $path $file | relURL }}" data-caption="{{ $caption }}"><img src="{{ path.Join $path $file | absURL }}"></a>
    <div class="caption">{{ $caption }}</div>
  </div>
{{ end }}
